<template>
  <div class="gk-layout-container">
    <div class="gk-layout-header">
      <!--工具栏-->
      <div class="toolbar" style="float:left;">
        <el-form :inline="true" :model="filters" :size="global.gSize">
          <el-form-item>
            <el-input v-model="filters.areaName" :placeholder="'请输入区域名称'" clearable></el-input>
          </el-form-item>
     
          <el-form-item>
            <el-input v-model="filters.orderNo" placeholder="仅可输入1,2,3进行查询" auto-complete="off" clearable
              onkeyup="value=value.replace(/[^1-3]/g,'')">
            </el-input>
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-search" :label="$t('action.search')" perms="corewh:corewharea:view" type="primary"
              @click="findPage(null)" />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-plus" :label="$t('action.add')" perms="corewh:corewharea:add" type="primary"
              @click="handleAdd" />
          </el-form-item>
        </el-form>
      </div>
      <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
        <el-form :inline="true" :size="global.gSize">
          <el-form-item>
            <el-button-group>
              <el-tooltip :content="$t('action.refresh')" placement="top">
                <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
              </el-tooltip>
              
              <!-- <el-tooltip content="导出" placement="top">
					<el-button icon="fa fa-file-excel-o"></el-button>
				</el-tooltip> -->
            </el-button-group>
          </el-form-item>
        </el-form>
        <!--表格显示列界面-->
       
      </div>
    </div>




    <div class="gk-layout-main">
      <my-table :data="pageResult.content" :loading="loading"  @selection-change="selectionChange">
          <el-table-column :label="$t('action.desc')" width="50"   header-align="center" align="center">
            <template slot-scope="scope">   {{scope.$index+1}}   </template>
          </el-table-column> 
          <el-table-column type="selection" width="40" ></el-table-column>
          <el-table-column  header-align="center"  align="center"  prop="areaName" :label="$t('field.Core.corewharea.areaName')"   key="areaName" >  </el-table-column>
           <el-table-column  header-align="center"  align="center"   prop="info" :label="$t('field.Core.corewharea.info')"   key="info" >  </el-table-column>
       <!--
           <el-table-column  header-align="center"  align="center"   prop="whId" :label="$t('field.Core.corewharea.whName')"     key="whId" >  </el-table-column>
    -->
           <el-table-column  header-align="center"  align="center"   prop="orderNo" :label="$t('field.Core.corewharea.orderNO')"     key="orderNo" >  </el-table-column>

          <el-table-column  header-align="center"  align="center"    :label="$t('action.operation')" >
              <template slot-scope="scope">
                <kt-delete-button    perms="corewh:corewharea:delete"  :size="global.gSize"   @click="handleDelete(scope.$index, scope.row)" />
                <kt-button icon="fa fa-edit"  :label="$t('action.edit')"  perms="corewh:corewharea:edit"    @click="handleEdit(scope.$index, scope.row)" />
              </template>
          </el-table-column>
      </my-table>
  </div>
  <!--分页栏-->
  <div class="toolbar gk-layout-footer"  style="padding:10px;">
    <kt-delete-button  perms="corewh:corewharea:delete" :size="global.gSize" type="danger"
    @click="handleBatchDelete()" disable style="float:left;" :disabled="this.selections.length==0" />
    <el-pagination layout="total, prev, pager, next, jumper"  @current-change="findPage"
                   :current-page="pageRequest.pageNum"
                   :page-size="pageRequest.pageSize"
                   :total="pageResult.totalSize"
                   style="float:right;">
    </el-pagination>
  </div>


    <!--新增编辑界面-->
    <el-dialog :title="operation?'库区 —— 新增':'库区 —— 编辑'" width="40%" :visible.sync="dialogVisible"
      :close-on-click-modal="false">
      <el-form :model="dataForm" label-width="90px" :rules="dataFormRules" ref="dataForm" :size="global.gSize"
        label-position="right">
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataForm.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item :label="$t('field.Core.corewharea.areaName')" prop="areaName">
          <el-input v-model="dataForm.areaName" auto-complete="off" clearable></el-input>
        </el-form-item>
     
        <el-form-item :label="$t('field.Core.corewharea.info')" prop="info">
          <el-input v-model="dataForm.info" auto-complete="off" clearable></el-input>
        </el-form-item>
       
        <el-form-item :label="$t('field.Core.corewharea.orderNO')" prop="orderNo">
          <el-input v-model="dataForm.orderNo" auto-complete="off" placeholder="排序"
            onkeyup="value=value.replace(/[^0-9]/g,'')" clearable></el-input>
        </el-form-item>
      
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="global.gSize" @click.native="dialogVisible = false">{{$t('action.cancel')}}</el-button>
        <el-button :size="global.gSize" type="primary" @click.native="submitForm" :loading="editLoading">{{$t('action.submit')}}
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import PopupTreeInput from "@/components/PopupTreeInput"
	import MyTable from "@/views/Core/MyTable"
  import KtButton from "@/views/Core/KtButton"
  import KtDeleteButton from "@/views/Core/KtDeleteButton"
 
  import { format } from "@/utils/datetime"
  export default {
    components: {
      PopupTreeInput,
      KtButton,
      KtDeleteButton,
 
      MyTable
    },
    data() {
      return {

        filters: {
          areaName: ''
        },
        dicts: [],
        columns: [],
        loading:false,
        filterColumns: [],
        selections :[],
        pageRequest: { pageNum: 1, pageSize: 40 },
        pageResult: {content:[]},

        operation: false, // true:新增, false:编辑
        dialogVisible: false, // 新增编辑界面是否显示
        editLoading: false,

        // 新增编辑界面数据
        dataForm: {
          id: 0,
          whId: '',
          areaName: '',
          craneId: '',
          info: '',
          orderNO: '',
          locWidth: '',
          locHight: '',
          locdeep: '',
          name: 'abcdef'
        }
        

      }
    },
    computed: {
      dataFormRules() {
        const dataFormRules = {
          name: [{ required: true, message: this.getKey("user.userInput"), trigger: 'blur' }]
        };
        return dataFormRules;
      }
    },
   
    methods: {
      // 获取分页数据
      findPage: function (data) {
        if (data !== null) {
          this.filters.pageNum = data 
        } else {
          this.filters.pageNum = 1
          this.pageRequest.pageNum = 1
        }
        this.filters.pageSize = this.pageRequest.pageSize
        this.$api.corewharea.findPage(this.filters).then((res) => {
          debugger
          this.pageResult = res.data

        }).then(data != null ? data.callback : '')
      },

      selectionChange: function (selection) {

this.selections = selection;
},
      handleBatchDelete: function () {
        let ids = this.selections.map(item => item.id).toString()
        let params = []
          let idArray = (ids + '').split(',')
          for (var i = 0; i < idArray.length; i++) {
            params.push({ 'id': idArray[i] })
          }
          this.$api.corewharea.batchDelete(params).then((res) => {
         if(res.code=="500"){

          this.$message({ message: this.getKey('action.operateFail') + res.msg, type: 'error' })
         }
         this.findPage(null)
        });
      },
      // 批量删除
      handleDelete: function (index ,data) {
        let params = [{ 'id': data.id }]
        
        this.$api.corewharea.batchDelete(params).then((res) => {
         if(res.code=="500"){

          this.$message({ message: this.getKey('action.operateFail') + res.msg, type: 'error' })
         }
         this.findPage(null)
        });
  
      },

      // 批量删除
     
      // 显示新增界面
      handleAdd: function () {
        this.dialogVisible = true
        this.operation = true
        this.dataForm = {
          id: 0,
          whId: '',
          areaName: '',
          craneId: '',
          info: '',
          orderNO: '',
          locWidth: '',
          locHight: '',
          locdeep: ''
        }
      },
      // 显示编辑界面
      handleEdit: function (params,row) {
        this.dialogVisible = true
        this.operation = false
        this.dataForm = Object.assign({}, row)
      },
      // 编辑
      submitForm: function () {
        this.$refs.dataForm.validate((valid) => {
          if (valid) {
            this.$confirm(this.getKey('action.isConfirm'), this.getKey('action.tips'), {}).then(() => {
              this.editLoading = true
              let params = Object.assign({}, this.dataForm)
              this.$api.corewharea.save(params).then((res) => {
                this.editLoading = false
                if (res.code == 200) {
                  this.$message({ message: this.getKey('action.operateSucess'), type: 'success' })
                  this.dialogVisible = false
                  this.$refs['dataForm'].resetFields()
                } else {
                  this.$message({ message: this.getKey('action.operateFail') + res.msg, type: 'error' })
                }
                this.findPage(null)
              })
            })
          }
        })
      },
      // 获取部门列表
      findDeptTree: function () {
        this.$api.dept.findDeptTree().then((res) => {
          this.deptData = res.data
        })
      },
      // 菜单树选中
      deptTreeCurrentChangeHandle(data, node) {
        this.dataForm.deptId = data.id
        this.dataForm.deptName = data.name
      },
      // 时间格式化
      dateFormat: function (row, column, cellValue, index) {
        return format(row[column.property])
      },
     
    
      // 处理表格列过滤显示
      handleFilterColumns: function (data) {
        this.filterColumns = data.filterColumns
        this.$refs.tableColumnFilterDialog.setDialogVisible(false)
      },
      getKey: function (arg) {
        return this.$t(arg)
      },
    

    },
    created() {
     

      this. findPage(null);
    }
  }
</script>

<style scoped>
</style>